package com.zx.designpattern.presenter;

import com.zx.designpattern.model.IBaseModel;
import com.zx.designpattern.model.impl.TagModelImpl;
import com.zx.designpattern.view.IBaseView;

import static com.zx.designpattern.model.impl.TagModelImpl.LoadCode.loadFromDB;
import static com.zx.designpattern.model.impl.TagModelImpl.LoadCode.postFormToDB;

/**
 * Created by zhoux on 2018/3/5.
 * 注释：
 */

public class TagsPresenter<T extends IBaseView> extends BasePresenter<T> {

    //model层引用
    TagModelImpl baseModel = new TagModelImpl();


    //UI逻辑1
    public void fetch() {
        if (baseView != null) {
            baseView.get().showLoading();
            if (baseModel != null) {
                baseModel.loadData(new IBaseModel.CallBack() {
                    @Override
                    public void success(Object data) {
                        baseView.get().showView(1, data);
                        baseView.get().hideLoading();
                    }

                    @Override
                    public void fail(Object data) {
                        baseView.get().hideLoading();

                    }
                });
            }
        }
    }


    public void testVolley() {
        if (baseView != null) {
            baseView.get().showLoading();
            if (baseModel != null) {
                baseModel.loadData(loadFromDB, new IBaseModel.CallBack() {
                    @Override
                    public void success(Object data) {
                        baseView.get().showView(1, data);
                        baseView.get().hideLoading();
                    }

                    @Override
                    public void fail(Object data) {
                        baseView.get().hideLoading();

                    }
                });
            }
        }
    }

    public void saveSomeTags(int nums) {
        if (baseView != null) {
            baseView.get().showLoading();
            if (baseModel != null) {
                baseModel.postData(postFormToDB, nums, new IBaseModel.CallBack() {
                    @Override
                    public void success(Object data) {
                        baseView.get().showView(1, data);
                        baseView.get().hideLoading();
                    }

                    @Override
                    public void fail(Object data) {
                        baseView.get().hideLoading();

                    }
                });
            }
        }
    }
}
